package org.igorno12.util.logging.test;

import org.igorno12.util.logging.Log4jLevelWrapper;

public final class Scaffolding {

	private static final Scaffolding INSTANCE = new Scaffolding();

	public static final Scaffolding getInstance() {
		return INSTANCE;
	}

	private Scaffolding() {
		super();
	}

	public void callLogger(org.apache.log4j.Logger logger,
			Log4jLevelWrapper wrapper, String message) {
		this.callLogger(logger, wrapper, message, null);
	}
	
	public void callLogger(org.apache.log4j.Logger logger,
			Log4jLevelWrapper wrapper, String message, Throwable thrown) {
		if (logger == null || wrapper == null || message == null) {
			throw new IllegalArgumentException();
		}
		switch (wrapper) {
		case ALL:
		case OFF:
			break;
		case DEBUG:
			if ( thrown == null) {
				logger.debug(message);
			} else {
				logger.debug(message, thrown);
			}
			break;
		case ERROR:
			if ( thrown == null) {
				logger.error(message);
			} else {
				logger.error(message, thrown);
			}
			break;
		case FATAL:
			if ( thrown == null) {
				logger.fatal(message);
			} else {
				logger.fatal(message, thrown);
			}
			break;
		case INFO:
			if ( thrown == null) {
				logger.info(message);
			} else {
				logger.info(message, thrown);
			}
			break;
		case TRACE:
			if ( thrown == null) {
				logger.trace(message);
			} else {
				logger.trace(message, thrown);
			}
			break;
		case WARN:
			if ( thrown == null) {
				logger.warn(message);
			} else {
				logger.warn(message, thrown);
			}
			break;
		default:
			throw new IllegalArgumentException(
					"unsupported instance of the enum " + wrapper);
		}
	}

}
